import { apisData, nodeData } from "./vo"
import ajax from "../../../modules/ajax";
import config from "../../../config.json"

export async function selectMock(projectId: number) : Promise<apisData> {
    try{
        let res = await ajax.ajax(config.requestUrl + "/gapi/folder/getList", {
            method : "GET",
            headers : {
                "Content-Type" : "application/json",
            },
            body:{
                projectId:projectId,
            }
        })
        if(!res.ok){
            return Promise.reject("net error");
        }
        return res.json();
    }catch(err: any) {
        console.log(err);
    }
    return Promise.reject("unknow error");
}

export async function getMockData(apiId: number) : Promise<nodeData> {
    try{
        let res = await ajax.ajax(config.requestUrl + "/gapi/api/get", {
            method : "GET",
            headers : {
                "Content-Type" : "application/json",
            },
            body:({
                apiId:apiId,
            })
        })
        if(!res.ok){
            return Promise.reject("net error");
        }
        return res.json();
    }catch(err: any) {
        console.log(err);
    }
    return Promise.reject("unknow error");
}